package com.wj.szcrm.controller;

import com.wj.szcrm.model.CURDResult;
import com.wj.szcrm.model.CourseOrder;
import com.wj.szcrm.model.PageResult;
import com.wj.szcrm.service.ICourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: WangJin
 * @description
 * @date: 2021/9/15 8:56
 */
//@RestController
    @Controller
@RequestMapping("/courseorder")
public class CourseController {

    @Autowired
    ICourseOrderService courseOrderService;

    @RequestMapping("/courselist")
    public String list(){
        return "courseorder/courselist";
    }

    @RequestMapping("/add")
    public String add(){
        return "courseorder/add";
    }


    @RequestMapping("/listJson")
    @ResponseBody
    public PageResult<CourseOrder> listJson(CourseOrder condition , int page,int limit){
        System.out.println(condition);
        PageResult<CourseOrder> result = courseOrderService.findPageResult(condition,page,limit);

        return result;
    }

    @RequestMapping("/save")
    @ResponseBody
    public CURDResult save(CourseOrder order){
        CURDResult result = new CURDResult();
        if(order.getOrder_id() == null || order.getOrder_id().length() == 0){
            courseOrderService.save(order);
        }else {
            courseOrderService.update(order);
        }
        return result;
    }

    @RequestMapping("/detail")
//    @ResponseBody
    public String detail(Model model , String order_id){
        CourseOrder order = courseOrderService.findByOrderId(order_id);
        model.addAttribute("order",order);
        return "courseorder/detail";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public CURDResult delete(String order_id){
        CURDResult result = new CURDResult();
        courseOrderService.deleteById(order_id);
        return result;
    }


    @RequestMapping("/edit")
    public String edit(Model model , String order_id){
        System.out.println("修改订单order_id" + order_id);
        CourseOrder order = courseOrderService.findByOrderId(order_id);
        model.addAttribute("order" , order);
        return "courseorder/edit";
    }

}

